package controller

import (
	"api/app/ctl/auto/v1/api"
	"api/app/ctl/service"
	"gitee.com/dreamwood/ez/server"
)

type AppHostController struct {
	api.AppHostApi
}

func init() {

	c := &AppHostController{}
	c.Prepare()
	c.AddRoute("/list", c.ListAction)
	c.AddRoute("/get", c.GetAction)
	c.AddRoute("/scan", c.ScanAction)
	c.AddRoute("/choice", c.ChoiceAction)
	c.AddRoute("/save", c.SaveAction)
	c.AddRoute(`/save_many`, c.SaveManyAction)
	c.AddRoute("/delete", c.DeleteAction)
	c.AddRoute("/delete_many", c.DeleteManyAction)
	c.AddRoute("/copy", c.CopyAction)
	c.AddRoute("/start", c.StartAction)
	c.AddRoute("/stop", c.StopAction)
	c.AddRoute("/create_starter", c.CreateStarterAction)
}

//如果不满意自动生成的方法，请自定义，本文件不会被生成器覆盖，请放心操作
//func (this *AppHostController) SaveAction(operation *server.Operation) {}
//func (this *AppHostController) GetAction(operation *server.Operation) {}
//func (this *AppHostController) ScanAction(operation *server.Operation) {}
//func (this *AppHostController) ListAction(operation *server.Operation) {}
//func (this *AppHostController) DeleteAction(operation *server.Operation) {}

func (c *AppHostController) StartAction(operation *server.Operation) {
	this := c.TakeOver(operation)

	id := this.Get("id").IsInt()

	e := service.Start(id)
	if this.Try(e) {
		return
	}
	this.ReturnSuccess("启动命令已下发", "")

}
func (c *AppHostController) StopAction(operation *server.Operation) {
	this := c.TakeOver(operation)

	id := this.Get("id").IsInt()

	e := service.Stop(id)
	if this.Try(e) {
		return
	}
	this.ReturnSuccess("终止命令已下发", "")

}
func (c *AppHostController) CreateStarterAction(operation *server.Operation) {
	this := c.TakeOver(operation)

	id := this.Get("id").IsInt()
	service.CreateStarterFromAppHost(id)

	this.ReturnSuccess("已创建", "")

}
